﻿using System;
using System.Collections.Generic;
using InvoiceInvoker.Logic.Repositories;
using NUnit.Framework;

namespace InvoiceInvoker.Logic.Tests.RepositoriesTests
{
	[TestFixture]
	public class InvoiceRepositoryTests
	{
		InvoiceRepository repository;

		[SetUp]
		public void TestsSetup()
		{
			repository = new InvoiceRepository(1);
		}
		
		[Test]
		public void Adds()
		{
			Customer customer = new Customer();
			customer.CompanyName = "test";

			Product product1 = new Product();
			Product product2 = new Product();
			Product product3 = new Product();
			product1.Name = "test";
			product2.Name = "test";
			product3.Name = "test";

			Invoice invoice = new Invoice();
			invoice.RegisteredSellerId = 1;
			invoice.CreationDate = DateTime.Today;
			invoice.Customer = customer;
			invoice.LeftToPay = 10.10M;
			invoice.Number = "test";
			invoice.Paid = 10.10M;
			invoice.PaymentCurrency = "test";
			invoice.PaymentDeadline = DateTime.Today;
			invoice.PaymentType = "test";
			invoice.Remarks = "test";
			invoice.SaleDate = DateTime.Today;
			invoice.Status = "test";
			invoice.ToPay = 10.10M;
			invoice.ToPayInWords = "test";

			invoice.Products.Add(product1);
			invoice.Products.Add(product2);
			invoice.Products.Add(product3);

			repository.Add(invoice);
		}

		[Test]
		public void GetsByExpression()
		{
			List<Invoice> result = repository.GetByExpression(i => i.PaymentType == "Type" && i.Number == "Number" && i.Customer.CompanyName == "CompanyName");
			Assert.AreEqual(2, result.Count);
		}

		[Test]
		public void GetsByCustomer()
		{
			List<Invoice> result = repository.GetByCustomer("Customer");
			Assert.AreEqual(2, result.Count);
		}

		[Test]
		public void GetsByDate()
		{
			List<Invoice> result = repository.GetByDate(new DateTime(2010, 8, 3), new DateTime(2010, 8, 4));
			Assert.AreEqual(2, result.Count);
		}

		[Test]
		public void GetsByProduct()
		{
			List<Invoice> result = repository.GetByProduct("Product");
			Assert.AreEqual(2, result.Count);
		}

		[Test]
		public void GetsByValue()
		{
			List<Invoice> result = repository.GetByValue(0.10M, 5.10M);
			Assert.AreEqual(3, result.Count);
		}
	}
}
